<!--  -->
<template>
  <div class="list-container">
    <el-form :inline="true" class="search-panel" ref="searchForm" v-model="searchObj">
      <el-form-item>
        <el-input
          v-model="searchObj.enterpriseName"
          style="width: 250px"
          placeholder="请输入成员账号/姓名/所属企业"
          @clear="getTenantList()"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getTenantList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button @click="resetData()">清空</el-button>
      </el-form-item>
    </el-form>
    <div class="table-panel">
      <el-row class="table-operate">
        <!-- <el-button size="small">新增人员</el-button> -->
        <router-link :to="'/tenant/add'">
          <el-button type="primary" icon="el-icon-plus">新增人员</el-button>
        </router-link>
      </el-row>
      <el-table :data="tableData" style="width: 100%" v-loading="loading">
        <el-table-column label="序号" width="55" align="center" type="index">
        </el-table-column>
        <el-table-column prop="username" label="成员账号" align="center">
        </el-table-column>
        <el-table-column prop="nickName" label="姓名" width="100" align="center">
        </el-table-column>

        <el-table-column prop="enterpriseName" label="所属企业" align="center">
        </el-table-column>
        <el-table-column prop="roleName" label="角色名称" align="center"> </el-table-column>
        <el-table-column prop="createBy" label="操作人" align="center"> </el-table-column>
        <el-table-column prop="createTime" label="添加时间" align="center"> </el-table-column>
        <!-- <el-table-column prop="updateTime" label="最后登录" align="center">
        </el-table-column> -->
        <el-table-column label="是否启用" width="100px" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              active-text="启用"
              active-color="#13ce66"
              active-value="0"
              inactive-value="1"
              @change="changeEnable(scope.row)"
            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="150" align="center">
          <template slot-scope="scope">
            <router-link :to="'/tenant/edit/'+scope.row.id">
              <el-button icon="el-icon-edit" type="text">编辑</el-button>
            </router-link>
            <el-button
              icon="el-icon-delete"
              type="text"
              @click="delTenant(scope.row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- <span>共{{totle/searchForm.pageSize}}页/{{totle}}条数据</span> -->
      <el-row class="page">
        <div class="page-tag">
            共{{ Math.ceil(total / pageSize) }}页/{{ total }}条数据
        </div>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </el-row>
      </div>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import card from "@/components/card/card";
import tenantApi from "@/api/tenant";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: { card },
  data() {
    //这里存放数据
    return {
      total: 0,
      name: "",
      department: null,
      pageSize: 10,
      currentPage: 1,
      sortMode: "",
      loading: true,
      searchObj: {}, // 查询表单对象
      tableData: [
        {
          // isDelete: true,
          // lastLoginTime: "2019/11/12 13:00",
          // addTime: "2019/11/12 13:00",
          // operator: "张三",
          // roleName: "VIP1",
          // enterpriseName: "企业1",
          // nickName: "李四",
          // username: "admin1",
        }
      ],
      sizeOptions: [5, 10, 15],
      sortModes: [],
      category:2,
      isAdmin:'1'

    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    handleCurrentChange() {
      console.log(this.currentPage);
      this.getTenantList();
    },
    handleSizeChange() {
      console.log(this.searchForm.pageSize);
      this.getTenantList();
    },
    getTenantList() {
      tenantApi.getTenantList(this.currentPage,this.pageSize,this.category,this.isAdmin,this.searchObj).then((res) => {
        this.tableData = res.data.items;
        this.total = res.data.total
        this.loading = false;

        // console.log(res.data);
      });
    },
    delTenant(id) {
      this.$confirm("是否确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
          tenantApi.deleteByIds(id).then((res) => {
            if (res.code === 200) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getTenantList()
            }
          }).catch(err => {
            this.$message({
                type: "error",
                message: err,
              });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    changeEnable(data){
      tenantApi.changeEnable(data.id).then(res => {
        if(res.code === 200){
          this.$message({
                type: "success",
                message: '修改成功',
              });
        }
      })
    },
    updateById(data) {
       this.$router.push({path:'/tenant/edit'})
    },
    resetData() {
      this.searchObj = {}
      this.getTenantList()
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getTenantList();
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style>
   .el-switch__core{
      height: 20px;
   }
   /* .center-bottom{
      margin-top:6%;
      text-align:center;
      color: #CCCCCC;
      font-size: 13px;
      margin-bottom: 2%;
    } */
</style>
